package com.ruoyi.jiuyvanrenwu.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.car.api.RemoteCarService;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.jiuyvanrenwu.domain.CheRescue;
import com.ruoyi.jiuyvanrenwu.service.ICheRescueService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 救援任务Controller
 * 
 * @author ruoyi
 * @date 2025-01-02
 */
@RestController
@RequestMapping("/jiuyvanrenwu")
public class CheRescueController extends BaseController
{
    @Autowired
    private ICheRescueService cheRescueService;

    @Autowired
    private RemoteCarService remoteCarService;

    /**
     * 查询救援任务列表
     */
    @RequiresPermissions("jiuyvanrenwu:jiuyvanrenwu:list")
    @GetMapping("/list")
    public TableDataInfo list(CheRescue cheRescue)
    {
        startPage();
        List<CheRescue> list = cheRescueService.selectCheRescueList(cheRescue);
        for (CheRescue cheRescue1 : list){
            cheRescue1.setCar(remoteCarService.getById(cheRescue1.getCarId(), SecurityConstants.FROM_SOURCE));
        }
        return getDataTable(list);
    }

    /**
     * 导出救援任务列表
     */
    @RequiresPermissions("jiuyvanrenwu:jiuyvanrenwu:export")
    @Log(title = "救援任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheRescue cheRescue)
    {
        List<CheRescue> list = cheRescueService.selectCheRescueList(cheRescue);
        ExcelUtil<CheRescue> util = new ExcelUtil<CheRescue>(CheRescue.class);
        util.exportExcel(response, list, "救援任务数据");
    }

    /**
     * 获取救援任务详细信息
     */
    @RequiresPermissions("jiuyvanrenwu:jiuyvanrenwu:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cheRescueService.selectCheRescueById(id));
    }

    /**
     * 新增救援任务
     */
    @RequiresPermissions("jiuyvanrenwu:jiuyvanrenwu:add")
    @Log(title = "救援任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheRescue cheRescue)
    {
        return toAjax(cheRescueService.insertCheRescue(cheRescue));
    }

    /**
     * 修改救援任务
     */
    @RequiresPermissions("jiuyvanrenwu:jiuyvanrenwu:edit")
    @Log(title = "救援任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheRescue cheRescue)
    {
        return toAjax(cheRescueService.updateCheRescue(cheRescue));
    }

    /**
     * 删除救援任务
     */
    @RequiresPermissions("jiuyvanrenwu:jiuyvanrenwu:remove")
    @Log(title = "救援任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cheRescueService.deleteCheRescueByIds(ids));
    }
}
